<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="75px">
      <el-form-item label="门店名称:" prop="storeName">
        <el-input v-model="queryParams.storeName" placeholder="请输入门店名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="所属区:" prop="regionString">
        <el-input v-model="queryParams.regionString" placeholder="请输入区名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="是否上架" prop="isInitiate">
        <el-input v-model="queryParams.isInitiate" placeholder="请输入是否上架" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:store:add']">新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:store:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:store:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:store:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="storeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="${comment}" align="center" prop="id" /> -->
      <el-table-column label="门店信息" prop="storeName" width="300" align="center">
        <template slot-scope="{row}">
          <div class="table-user">
            <div class="table-user-img">
              <image-preview :src="row.images" class="img" />
            </div>
            <div>
              <div>名称：{{ row.storeName }}</div>
              <div>联系电话：{{ row.phoneNumber }}</div>
              <div>详细地址：{{ row.detail }}</div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="营业时间" align="center" prop="openingTime">
        <template slot-scope="{row}">
          {{ row.openingTime + ' - ' + row.closingTime }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="联系电话" align="center" prop="phoneNumber" width="110" /> -->
      <!-- <el-table-column label="省" align="center" prop="province" />
      <el-table-column label="省名称" align="center" prop="provinceString" />
      <el-table-column label="市" align="center" prop="city" />
      <el-table-column label="市名称" align="center" prop="cityString" />
      <el-table-column label="区" align="center" prop="region" /> -->
      <el-table-column label="所属区" align="center" prop="regionString" />
      <!-- <el-table-column label="详细地址" align="center" prop="detail"  :show-overflow-tooltip='true' /> -->
      <!-- <el-table-column label="经度" align="center" prop="longitude" />
      <el-table-column label="纬度" align="center" prop="latitude" /> -->
      <!-- <el-table-column label="门店图片" align="center" prop="images" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.images" :width="50" :height="50" />
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="状态" align="center" prop="status" /> -->


      <!-- <el-table-column label="审核状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 1">审核通过</span>
          <span v-if="scope.row.status == 2">审核不通过</span>
          <span v-if="scope.row.status == 0">待审核</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="关门时间" align="center" prop="closingTime" /> -->
      <!-- <el-table-column label="配送范围" align="center" prop="deliveryScope" /> -->
      <!-- <el-table-column label="收款码图片" align="center" prop="collectionCode" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.collectionCode" :width="50" :height="50"/>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="店铺标签，以逗号隔开" align="center" prop="storeTags" /> -->
      <!-- <el-table-column label="排序" align="center" prop="sortNo" /> -->


      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column label="门店标签" align="center" prop="">
        <template slot-scope="{row}" v-if="row.tegNames !== '' && row.tegNames !== null">
          <el-tag v-for="(item, index) in row.tegNames.split(',')" :key="index" size="mini"
            style="margin-right: 5px; margin-top: 2px">{{ item }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="营业类型" align="center" prop="" width="300">
        <template slot-scope="{row}" v-if="row.typeTag !== '' && row.typeTag !== null">
          <el-tag v-for="(item, index) in row.typeTag.split(',')" :key="index" size="mini"
            style="margin-right: 5px; margin-top: 2px">{{ item }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="门店二维码" align="center" prop="storeQrCodeUrl" width="70">
        <template slot-scope="scope">
          <image-preview :src="scope.row.storeQrCodeUrl" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="评分" align="center" prop="score" />
      <el-table-column label="是否上架" align="center" prop="isInitiate">
        <template slot-scope="scope">
          <span v-if="scope.row.isInitiate == 0">已上架</span>
          <span v-if="scope.row.isInitiate != 0">不上架</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="营业类型" align="center" prop="typeTag" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleAudit(scope.row, 1)"
            v-if="scope.row.status == 0" v-hasPermi="['system:store:audit']">审核通过</el-button>

          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleAudit(scope.row, 2)"
            v-if="scope.row.status == 0" v-hasPermi="['system:store:audit']">审核不通过</el-button> -->


          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:store:edit']">修改</el-button>


          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="downloadQr(scope.row.row)">下载二维码</el-button> -->


          <!-- <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:store:remove']">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改门店对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>

      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">

        <el-tab-pane label="门店详情" name="store">
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="门店名称" prop="storeName">
                  <el-input v-model="form.storeName" placeholder="请输入门店名称" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="联系电话" prop="phoneNumber">
                  <el-input v-model="form.phoneNumber" placeholder="请输入联系电话" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-form-item label="门店图片" prop="images">
                <image-upload v-model="form.images" :limit="1" />
              </el-form-item>
            </el-row>
            <el-row>
              <el-form-item label="营业执照" prop="licenseImg">
                <image-upload v-model="form.licenseImg" />
              </el-form-item>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="所属省" prop="province">
                  <el-select v-model="form.province" placeholder="请选择" @change="getCitys">
                    <el-option v-for="item in provinces" :key="item.id" :label="item.cityName"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="所属市" prop="city">
                  <el-select v-model="form.city" placeholder="请选择" @change="getregions">
                    <el-option v-for="item in citys" :key="item.id" :label="item.cityName" :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="所属区" prop="region">
                  <el-select v-model="form.region" placeholder="请选择">
                    <el-option v-for="item in regions" :key="item.id" :label="item.cityName"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="16">
                <el-form-item label="详细地址" prop="detail">
                  <el-input type="textarea" v-model="form.detail" placeholder="请输入详细地址" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否上架" prop="isInitiate">
                  <el-radio-group v-model="form.isInitiate">
                    <el-radio :label="0">上架</el-radio>
                    <el-radio :label="1">不上架</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>

            <a href="http://jingweidu.757dy.com/" style="color:red;padding-left: 10%;" target=" _top">不知道经纬度请点击我</a>

            <el-row>
              <el-col :span="12">
                <el-form-item label="经度" prop="longitude">
                  <el-input v-model="form.longitude" placeholder="请输入经度" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="纬度" prop="latitude">
                  <el-input v-model="form.latitude" placeholder="请输入纬度" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row>
              <el-col :span="12">
                <el-form-item label="配送费" prop="freight">
                  <el-input v-model="form.freight" placeholder="请输入配送费" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
<!--                <el-form-item label="加急配送费" prop="urgentCharge" label-width="100px">-->
<!--                  <el-input v-model="form.urgentCharge" placeholder="请输入加急配送费" />-->
<!--                </el-form-item>-->
                <el-form-item label="门店标签" prop="tagIds">
                  <el-select v-model="form.tagIds" multiple placeholder="请选择" style="width: 100%;">
                    <el-option v-for="item in tagNameOptions" :key="item.tagName" :label="item.tagName"
                               :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="开门时间" prop="openingTime">
                  <!-- <el-input v-model="form.openingTime" placeholder="请输入开门时间" /> -->
                  <el-time-select v-model="form.openingTime" :picker-options="{
                    start: '00:00',
                    step: '00:10',
                    end: '24:00'
                  }" placeholder="选择时间" style="width: 100%;">
                  </el-time-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="关门时间" prop="closingTime">
                  <!-- <el-input v-model="form.closingTime" placeholder="请输入关门时间" /> -->
                  <el-time-select v-model="form.closingTime" :picker-options="{
                    start: '00:00',
                    step: '00:10',
                    end: '24:00'
                  }" placeholder="选择时间" style="width: 100%;">
                  </el-time-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="营业类型" prop="typeTagIds">
                  <el-select v-model="form.typeTagIds" multiple placeholder="请选择" style="width: 100%;">
                    <el-option v-for="item in typeTagOptions" :key="item.tagName" :label="item.tagName"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <!-- <el-row>
              <el-col :span="12">
                <el-form-item label="全部标签" prop="storeTags">
                  <el-select v-model="form.storeTags" multiple placeholder="请选择" style="width: 100%;">
                    <el-option v-for="item in storeTagOptions" :key="item.tagName" :label="item.tagName"
                      :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row> -->
            <!-- <el-row>
              <el-col :span="12">
                <el-form-item label="评分" prop="score">
                  <el-input v-model="form.score" placeholder="请输入评分" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="排序" prop="sortNo">
                  <el-input v-model="form.sortNo" placeholder="请输入排序" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="备注" prop="remark">
                  <el-input v-model="form.remark" placeholder="请输入备注" />
                </el-form-item>
              </el-col>
            </el-row> -->
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="分销团队" name="distribution">
          <h1>门店分销团队总数：<span id="team-total">{{ distributionTotal }}</span></h1>
          <el-table v-loading="distributionLoading" :data="distributionList">
            <el-table-column label="用户名称" align="center" prop="userName" />
            <el-table-column label="用户手机号" align="center" prop="phoneNumber" />
            <el-table-column label="加入时间" align="center" prop="createDate" />

          </el-table>
        </el-tab-pane>

        <el-tab-pane label="提现账号管理" name="withdrawal">
          <el-button type="primary" @click="addColumn">添加</el-button>
          <el-button type="danger" @click="deleteColumn">删除</el-button>


          <el-table :data="withdrawalList" @selection-change="handlewithdrawalList">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="支付宝账号" align="center" prop="withdrawNum">
              <template slot-scope="scope">
                <el-input v-model="scope.row.withdrawNum"></el-input>
              </template>
            </el-table-column>

            <el-table-column label="收款名称" align="center" prop="withdrawName">
              <template slot-scope="scope">
                <el-input v-model="scope.row.withdrawName"></el-input>
              </template>
            </el-table-column>

          </el-table>
        </el-tab-pane>
      </el-tabs>



      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStore, getStore, delStore, addStore, updateStore, listUser, listAccount, addAccount } from "@/api/fx/store";
import { listChina } from "@/api/fx/china";
import { listTag } from "@/api/fx/tag";
export default {
  name: "Store",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 门店表格数据
      storeList: [],
      //修改里面的tab
      activeName: 'store',
      //分销团队loading
      distributionLoading: false,
      //分销团队总数
      distributionTotal: '',
      //分销团队list
      distributionList: [],
      //体现管理的list
      withdrawalList: [],
      storeTagOptions: [],
      tagNameOptions: [],
      typeTagOptions: [],
      provincelist: [],
      cityslist: [],
      regionslist: [],
      provinces: [],
      citys: [],
      regions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storeName: null,
        phoneNumber: null,
        province: null,
        provinceString: null,
        city: null,
        cityString: null,
        region: null,
        regionString: null,
        detail: null,
        longitude: null,
        latitude: null,
        intro: null,
        images: null,
        status: 1,
        isInitiate: null,
        openingTime: null,
        closingTime: null,
        deliveryScope: null,
        collectionCode: null,
        storeTags: null,
        score: null,
        sortNo: null,
      },
      // 表单参数
      form: {},
      //selection
      selectionlList: [],
      // 表单校验
      rules: {
        storeName: [
          { required: true, message: "门店名称不能为空", trigger: "blur" }
        ],
        regionString: [
          { required: true, message: "所属区不能为空", trigger: "blur" }
        ],
        detail: [
          { required: true, message: "详细地址不能为空", trigger: "blur" }
        ],
        deliveryScope: [
          { required: true, message: "配送范围不能为空", trigger: "blur" }
        ],
        province: [
          { required: true, message: "所属省不能为空", trigger: "blur" }
        ],
        city: [
          { required: true, message: "所属市不能为空", trigger: "blur" }
        ],
        region: [
          { required: true, message: "所属区不能为空", trigger: "blur" }
        ],
        longitude: [
          { required: true, message: "经度不能为空", trigger: "blur" }
        ],
        latitude: [
          { required: true, message: "纬度不能为空", trigger: "blur" }
        ],
        isInitiate: [
          { required: true, message: "请选择是否上架", trigger: "blur" }
        ],
        openingTime: [
          { required: true, message: "开门时间不能为空", trigger: "blur" }
        ],
        closingTime: [
          { required: true, message: "关门时间不能为空", trigger: "blur" }
        ],
        freight: [
          { required: true, message: "配送费不能为空", trigger: "blur" },
          { pattern: /^\d+(\.\d{1,3})?$/, message: "配送费最多保留三位小数", trigger: "blur" }
        ],
        urgentCharge: [
          { required: true, message: "加急配送费不能为空", trigger: "blur" },
          { pattern: /^\d+(\.\d{1,3})?$/, message: "加急配送费最多保留三位小数", trigger: "blur" }
        ],
        images: [
          { required: true, message: "门店图片不能为空", trigger: "blur" }
        ]
      },
      chinaList: [],
    };
  },
  created() {
    this.getList();
    this.getlistChina();
  },
  methods: {
    // 获取省市区的数据

    getlistChina() {
      var queryParams1 = {
        pageNum: 1,
        pageSize: 10000,
      };
      listChina(queryParams1).then(response => {
        let list = this.handleTree(response.rows, "id");
        this.chinaList = list;
        this.provinces = list[0].children;
        this.cityslist = list[0].children[0].children;
        this.regionslist = list[0].children[0].children[0].children;
        this.citys = list[0].children[0].children;
        this.regions = list[0].children[0].children[0].children;

        // this.provinces = response.rows.filter(item => item.depth == 1 && item.id == '420000');
        // this.cityslist = response.rows.filter(item => item.depth == 2 && item.id == "420100");
        // this.regionslist = response.rows.filter(item => item.depth == 3 && item.parentId == "420100");
        // this.citys = response.rows.filter(item => item.depth == 2 && item.id == "420100");
        // this.regions = response.rows.filter(item => item.depth == 3 && item.parentId == "420100");
      });

    },
    addColumn() {
      this.withdrawalList.push({ withdrawNum: '', withdrawName: '' });
    },
    deleteColumn() {
      this.withdrawalList = this.withdrawalList.filter(row => !this.selectionlList.includes(row));
    },
    //提现账号列表change
    handlewithdrawalList(selection) {
      console.log(selection, '提现账号列表');
      this.selectionlList = selection
    },
    handleClick(tab, event) {
      if (tab) {
        this.activeName = tab._props.name
      }
      if (this.activeName == 'distribution') {
        let params = {
          distributionId: this.form.id
        }
        listUser(params).then(res => {
          if (res.code == 200) {
            this.distributionList = res.rows
            this.distributionTotal = res.rows.length
          }
        })
      } else if (this.activeName == 'withdrawal') {
        let params = {
          merchantId: this.form.id
        }
        listAccount(params).then(res => {
          this.withdrawalList = res.data
        })
      }
    },
    getCitys(value) {
      let list = this.chinaList[0].children;
      let index = list.map(item => item.id).indexOf(value);
      this.cityIndex = index;
      this.citys = list[index].children;

      // this.citys = this.cityslist.filter(item => parseInt(item.parentId) == parseInt(value));
      // this.form.city = '';
      // this.form.region = '';
    },

    getregions(value) {
      let list = this.chinaList[0].children[this.cityIndex].children;
      let index = list.map(item => item.id).indexOf(value);
      this.regions = list[index].children;

      // this.regions = this.regionslist.filter(item => parseInt(item.parentId) == parseInt(value));
      // this.form.region = '';
    },

    /** 查询门店列表 */
    getList() {
      this.loading = true;
      listStore(this.queryParams).then(response => {
        this.storeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      var queryParams = {
        pageNum: 1,
        pageSize: 100,
      };
      var queryParams1 = {
        type: "3",
        pageNum: 1,
        pageSize: 100,
      };
      var queryParams2 = {
        type: "2",
        pageNum: 1,
        pageSize: 100,
      };
      listTag(queryParams).then(response => {
        console.log('11111');
        console.log(response.rows);
        this.storeTagOptions = response.rows.filter(item => item.type != "1");
        console.log(this.storeTagOptions);
      });
      listTag(queryParams1).then(response => {
        console.log('门店标签');
        console.log(response.rows);
        this.tagNameOptions = response.rows;
        console.log(this.tagNameOptions);
      });
      listTag(queryParams2).then(response => {
        console.log('营业类型');
        console.log(response.rows);
        this.typeTagOptions = response.rows;
        console.log(this.typeTagOptions);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        storeName: null,
        phoneNumber: null,
        province: null,
        provinceString: null,
        city: null,
        cityString: null,
        region: null,
        regionString: null,
        detail: null,
        longitude: null,
        latitude: null,
        intro: null,
        images: null,
        status: 1,
        isInitiate: null,
        openingTime: null,
        closingTime: null,
        deliveryScope: null,
        collectionCode: null,
        typeTagIds: null,
        tagIds: null,
        score: null,
        freight: null,
        sortNo: null,
        createTime: null,
        remark: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加门店";
    },

    handleAudit(row, auditState) {
      this.resetForm("form");
      this.form.id = row.id;
      this.form.status = auditState;
      updateStore(this.form).then(response => {
        this.$modal.msgSuccess("已审核");
        this.open = false;
        this.getList();
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      console.log(this.activeName, 'activeName```````');

      getStore(id).then(response => {
        this.form = response.data;
        console.log("查看 form 表单：" + this.form.tagIds);
        console.log("查看 form 表单：" + this.form.typeTagIds);
        console.log(this.form.storeTags);
        let result = [];
        let tagId = [];
        let typeTagId = [];
        if (this.form.tagIds != null && this.form.tagIds !== '') {
          this.form.tagIds.split(',').forEach(item => {
            tagId.push(parseInt(item));
          });
        }
        if (this.form.typeTagIds != null && this.form.typeTagIds !== '') {
          this.form.typeTagIds.split(',').forEach(item => {
            typeTagId.push(parseInt(item));
          });
        }
        if (this.form.storeTags != null) {
          this.form.storeTags.split(',').forEach(item => {
            result.push(parseInt(item));
          });
        }

        this.form.storeTags = result
        this.form.tagIds = tagId
        this.form.typeTagIds = typeTagId
        this.form.isInitiate = parseInt(this.form.isInitiate)
        this.form.province = parseInt(this.form.province)
        this.form.city = parseInt(this.form.city)
        this.form.region = parseInt(this.form.region)
        this.getCitys(this.form.province);
        setTimeout(()=>{
          this.getregions(this.form.city);
        }, 100)
        // console.log(this.form.storeTags);
        this.open = true;
        this.title = "修改门店";
        this.handleClick()
      });

    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {

        console.log("表单内容：" + this.form)
        if (valid) {
          if (this.activeName == 'withdrawal') {
            this.withdrawalList.map(item => {
              item.merchantId = this.form.id
              item.merchantName = this.form.storeName
            })
            addAccount(this.withdrawalList).then(res => {
              console.log(res, '提交提现账号的res');

            })
          }

          if (this.form.city) {
            this.form.cityString = this.cityslist.filter(item => parseInt(item.id) == parseInt(this.form.city)).map(item=>item.cityName)[0]||"";
          }

          if (this.form.province) {
            this.form.provinceString = this.provinces.filter(item => parseInt(item.id) == parseInt(this.form.province)).map(item=>item.cityName)[0]||"";
          }

          if (this.form.region) {
            this.form.regionString = this.regionslist.filter(item => parseInt(item.id) == parseInt(this.form.region)).map(item=>item.cityName)[0]||"";
          }

          if (this.form.id != null) {
            console.log(this.form.tagIds)
            console.log(this.form.typeTagIds)
            if (this.form.tagIds || this.form.typeTagIds) {
              this.form.storeTags = (this.form.tagIds || []).concat(this.form.typeTagIds || []).join(',');
              this.form.tagIds = this.form.tagIds.join(',');
              this.form.typeTagIds = this.form.typeTagIds.join(',');

            }
            console.log(this.form, 8888888888);

            updateStore(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.storeTags = this.form.storeTags.join(',');
            addStore(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }

        }
      });
    },
    //下载二维啊
    downloadQr(row) {
      this.downloadByBlob("http://47.121.199.55:8088/profile/upload/barCode/2024/08/29/991a7933-e514-4e6e-9927-6e065d2652b0.png", "测试");
    },

    downloadByBlob(url, name) {
      let image = new Image()
      image.setAttribute('crossOrigin', 'anonymous')
      image.src = url
      image.onload = () => {
        let canvas = document.createElement('canvas')
        canvas.width = image.width
        canvas.height = image.height
        let ctx = canvas.getContext('2d')
        ctx.drawImage(image, 0, 0, image.width, image.height)
        canvas.toBlob((blob) => {
          let url = URL.createObjectURL(blob)
          this.download(url, name)
          // 用完释放URL对象
          URL.revokeObjectURL(url)
        })
      }
      function download(href, name) {
        let eleLink = document.createElement('a')
        eleLink.download = name
        eleLink.href = href
        eleLink.click()
        eleLink.remove()
      }
    },


    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除门店编号为"' + ids + '"的数据项？').then(function () {
        return delStore(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/store/export', {
        ...this.queryParams
      }, `store_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lange="sass" scoped>
.table-user {
  width: 100%;
  height: 100%;
  display: flex;
  /* justify-content: center; */
  align-items: center;
  text-align: left !important;

  .table-user-img {
    width: 2vw;
    height: 4vh;
    margin-right: 10px;

    .img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      object-fit: cover;
      overflow: hidden;
    }
  }

}
</style>
